import G6 from "@antv/g6";
import {taskArr, anchor, gatewayArr, eventArr} from "components/flowChartDetailNew/flowConfig";


export function initNodes() {
  G6.registerNode(
    'task-node',
    {
      drawShape(cfg, group) {

        const width = 58;
        const height = 40;
        const x = -width / 2;
        const y = -height / 2;
        const rect = group.addShape('rect', {
          attrs: {
            x,
            y,
            width,
            height,
            radius: 4,
            stroke: "#ee622b",
            fill: '#fff',
            lineWidth: 3,
          },
          name: 'rect-shape',
        });

        if (cfg.name) {
          group.addShape('text', {
            attrs: {
              text: cfg.name,
              x: 0,
              y: 0,
              fill: '#00287E',
              fontSize: 14,
              textAlign: 'center',
              textBaseline: 'middle',
              fontWeight: 'bold',
              stroke: '#fff',
            },
            name: 'text-shape',
          });
        }
        return rect;
      },

    },
    'single-node',
  );

  taskArr.forEach((item) => {
    G6.registerNode(
      item.shape,
      {
        drawShape(cfg, group) {

          const width = 58;
          const height = 40;
          const x = -width / 2;
          const y = -height / 2;
          const rect = group.addShape('rect', {
            attrs: {
              x,
              y,
              width,
              height,
              radius: 4,
              stroke: "#ee622b",
              fill: '#fff',
              lineWidth: 3,
            },
            name: 'rect-shape',
          });
          return rect;
        },

        label: item.label,
        color_type: item.color_type,
        type_icon_url: item.type_icon_url,
        // 设置锚点
        anchor: item.anchor || anchor,
      },
      "task-card",
    );
  });

  taskArr.forEach((item) => {
    G6.registerNode(
      item.activeShape,
      {
        label: item.label,
        color_type: item.color_type,
        type_icon_url: item.type_icon_url,
        // 设置锚点
        anchor: item.anchor || anchor,
      },
      "task-active",
    );
  });

  gatewayArr.forEach((item) => {
    G6.registerNode(
      item.shape,
      {
        label: item.label,
        color_type: item.color_type,
        type_icon_url: item.type_icon_url,
        // 设置锚点
        anchor: item.anchor || anchor,
      },
      "gateway-card",
    );
  });

  eventArr.forEach((item) => {
    G6.registerNode(
      item.shape,
      {
        label: item.label,
        color_type: item.color_type,
        type_icon_url: item.type_icon_url,
        // 设置锚点
        anchor: item.anchor || anchor,
      },
      "event-card",
    );
  });
}


